const util = require('../../utils/util.js');
const Toast = require('../../utils/toast.js');
Page({
  data: {
    lessonlist: []
  },
  onLoad: function (option) {
    this.schoollist();
  },
  schoollist: function () {
    let that = this;
    util.request('/index/getindexlessonlist', {
      page: that.data.currentPage
    }, 'GET').then(function (res) {
      //判断是否有数据，有则取数据
      if (res.errno === 0 && res.data.lessonlist.length != 0) {
        
        that.setData({
          lessonlist: res.data.lessonlist //获取数据数组
        });
        //没有数据了，把“没有数据”显示，把“上拉加载”隐藏
      } else {
        console.log('没有数据了')
      }
    });
  },
  // //下拉刷新
  // onPullDownRefresh: function () {
  //   let that = this;
  //   wx.showNavigationBarLoading() //在标题栏中显示加载
  //   setTimeout(function () {
  //     that.setData({
  //       currentPage: 1,
  //       isFromSearch: true,
  //       isHideLoadMore: true, //"上拉加载"的变量，默认true，隐藏
  //       isHideLoadComplete: false //“没有数据”的变量，默认false，隐藏
  //     })
  //     that.schoollist()
  //     wx.hideNavigationBarLoading() //完成停止加载
  //     wx.stopPullDownRefresh() //停止下拉刷新
  //     Toast('下拉刷新完成', 'noicon')
  //   }, 1500);
  // },
  // //滚动到底部触发事件
  // onReachBottom: function () {
  //   let that = this;
  //   if (!that.data.isHideLoadMore && !that.data.isHideLoadComplete) {
  //     that.setData({
  //       currentPage: that.data.currentPage + 1, //每次触发上拉事件，把searchPageNum+1
  //       isFromSearch: false //触发到上拉事件，把isFromSearch设为为false
  //     });
  //     that.schoollist();
  //   }
  // },
  toLessoninfo: function (e) {
    let lesson_id = e.currentTarget.dataset.id;
    wx.navigateTo({
      url: '/pages/lessoninfo/lessoninfo?id=' + lesson_id
    })
  }
})